﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;


namespace SanguoSharp.Server
{
    public static class ServerUtils
    {
        public const int InterfaceVersionMajor = 1;
        public const int InterfaceVersionMinor = 0;

        public static bool IsServerCompatible(IServerBase server)
        {
            if (server.ServerInterfaceVersionMajor != InterfaceVersionMajor)
                return false;
            if (server.ServerInterfaceVersionMinor < InterfaceVersionMinor)
                return false;
            return true;
        }

        public static Type[] ClientSharedTypes = new Type[]
		{
		};
        public static Type[] ServerSharedTypes = new Type[]
		{
			typeof(IServerBase),
			typeof(IServerAdmin),
			typeof(ISessionAdmin),
		};

        public static IServerBase ConnectAdmin(string address, int port)
        {
            return Utils.Connect<IServerBase>("127.0.0.1", address, port, Utils.ClientSharedTypes.Concat(ClientSharedTypes));
        }
        public static void ServeAdmin<T>(int port, IPAddress bindTo)
            where T : MarshalByRefObject, new()
        {
            Utils.Serve<T>("127.0.0.1", port, Utils.ServerSharedTypes.Concat(ServerSharedTypes), bindTo);
        }
    }
}
